<template>
  <div class="container" style="padding-top: 0">
    <div class="banner" v-if="this.uid">
      <van-cell-group class="my-info">
        <van-cell class="base-info" center :border="false">
          <van-image
            class="avatar"
            slot="icon"
            round
            fit="cover"
            :src="list.avatar"
          />
          <div class="name" slot="title">{{ list.nickname }}</div>
          <van-button class="update-btn" size="small" round to="/user/edit"
            >编辑资料</van-button
          >
        </van-cell>
        <van-grid class="data-info" :border="false" column-num="2">
          <van-grid-item class="data-info-item">
            <div slot="text" class="text-wrap">
              <div class="count">{{ list1.publish_num }}</div>
              <router-link class="toutiao" to="/irelease"
                ><div class="text">头条</div></router-link
              >
            </div>
          </van-grid-item>
          <van-grid-item class="data-info-item">
            <div class="text-wrap" slot="text">
              <div class="count">{{ list1.liked_num }}</div>
              <div class="text">获赞</div>
            </div>
          </van-grid-item>
        </van-grid>
      </van-cell-group>
    </div>
    <div class="not-login" v-if="!this.uid">
      <div>
        <img class="mobile" src="../assets/tel.png" />
      </div>
      <div class="text">
        <router-link class="denglu" to="/login">登录</router-link> /<router-link
          class="denglu"
          to="/reg"
          >注册</router-link
        >
      </div>
    </div>

    <van-grid class="nav-grid mb-4" :column-num="2">
      <van-grid-item class="nav-grid-item">
        <van-icon name="star-o" />
        <router-link class="shoucang" to="/collectlist"
          ><span>收藏</span></router-link
        >
      </van-grid-item>
      <van-grid-item class="nav-grid-item">
        <van-icon name="clock-o" />
        <router-link class="shoucang" to="/history"
          ><span>历史</span></router-link
        >
      </van-grid-item>
    </van-grid>
    <van-cell title="修改密码" is-link to="/changepassword" />
    <van-cell title="联系我们" is-link to="/" />
    <van-cell class="mb-4" title="关于我们" is-link to="/" />
    <van-cell class="logout-cell" title="退出登录" @click="logOut" />
    <van-tabbar v-model="active2">
      <van-tabbar-item icon="home-o" to="/">首页</van-tabbar-item>
      <van-tabbar-item icon="add-o" to="/publish">发布</van-tabbar-item>
      <van-tabbar-item icon="friends-o" to="/my">我的</van-tabbar-item>
    </van-tabbar>
  </div>
</template>

<script>
export default {
  data() {
    return {
      list: [],
      list1: [],
      active2: "",
      uid: "",
    };
  },
  mounted() {
    this.token = localStorage.getItem("token");
    this.uid = localStorage.getItem("uid");
    this.axios.post("/user/getuserInfo", { token: this.token }).then((res) => {
      console.log(res);
      this.list = res.data.userInfo;
      this.list1 = res.data;
      console.log(this.list);
    });
  },
  methods: {
    logOut() {
      window.localStorage.clear();
      this.$toast("退出登录成功");
      setTimeout((v) => {
        this.$router.push("/login");
      }, 500);
    },
  },
};
</script>

<style  lang="less" >
.denglu {
  color: #fff;
  font-size: 16px;
}
// .banner {
//   background: url("../assets/banner.jpg") no-repeat;
// }
.container {
  .my-info {
    background: url("../assets/banner.jpg") no-repeat;
    background-size: cover;
    .base-info {
      box-sizing: border-box;
      height: 115px;
      background-color: unset;
      padding-top: 38px;
      padding-bottom: 11px;
      .avatar {
        box-sizing: border-box;
        width: 66px;
        height: 66px;
        border: 1px solid #fff;
        margin-right: 11px;
      }
      .name {
        font-size: 15px;
        color: #fff;
      }
      .update-btn {
        height: 24px;
        font-size: 12px;
        color: #666666;
      }
    }
    .data-info {
      .data-info-item {
        height: 65px;
        color: #fff;
        .text-wrap {
          display: flex;
          flex-direction: column;
          justify-content: center;
          align-items: center;
          .count {
            font-size: 18px;
          }
          .text {
            font-size: 11px;
          }
        }
      }
    }
    .van-grid-item__content {
      background-color: unset;
    }
  }

  .not-login {
    height: 180px;
    background: url("../assets/banner.jpg") no-repeat;
    background-size: cover;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    // width: 100%;
    // margin: auto;
    // padding-left: 40.33333vw;
    // padding-top: 40px;
    .mobile {
      width: 66px;
      height: 66px;
    }
    .text {
      font-size: 14px;
      color: #fff;
    }
  }

  .nav-grid {
    .nav-grid-item {
      height: 70px;
      .iconfont {
        font-size: 22px;
        margin-bottom: 5px;
      }
      .icon-shoucang {
        color: #eb5253;
      }
      .icon-lishi {
        color: #ff9d1d;
      }
      .van-grid-item__text {
        font-size: 14px;
        color: #333333;
      }
    }
  }

  .logout-cell {
    text-align: center;
    color: #d86262;
  }
  .mb-4 {
    margin-bottom: 4px;
  }
  .toutiao {
    color: #fff;
  }
  .shoucang {
    color: #000;
  }
}
</style>
